<?php
declare (strict_types = 1);

namespace app\common\system\logic;

use app\common\BaseLogic;
use app\common\system\model\AuthNode;

class AuthNodeLogic extends BaseLogic {

    public function getMenuItems()
    {
        $where = [];
        $where[] = ['type', '=', '1'];
        $where[] = ['status', '=', '1'];
        $model = new AuthNode();
        $list = $model->where($where)->order('sort')->select();
        if ($list->isEmpty()) {
            return [];
        } else {
            foreach ($list as $key => &$row) {
                $row->append(['meta']);
            }

            return $list->toArray();
        }
    }

    public function getAdminNode()
    {
        $where = [];
        $where[] = ['status', '=', 1];
        $where[] = ['type', '<>', 1];
        $model = new AuthNode();
        $list = $model->where($where)->select();

        return $list->toArray();

    }

    public function getNodeByIds($ids)
    {
        $where = [];
        $where[] = ['status', '=', 1];
        $where[] = ['type', '<>', 1];
        $where[] = ['id', 'in', $ids];
        $model = new AuthNode();
        $list = $model->where($where)->select();

        if ($list->isEmpty()) {
            return [];
        } else {

            foreach ($list as $key => &$row) {
                $row->append(['meta']);
            }
            return $list->toArray();
        }
    }

    public function getMenuByIds($ids)
    {
        $where = [];
        $where[] = ['status', '=', 1];
        $where[] = ['type', '=', 1];
        $where[] = ['id', 'in', $ids];
        $model = new AuthNode();
        $list = $model->where($where)->select();

        if ($list->isEmpty()) {
            return [];
        } else {
            foreach ($list as $key => &$row) {
                $row->append(['meta']);
            }
            return $list->toArray();
        }
    }

    public function getFucByIds($ids)
    {
        $where = [];
        $where[] = ['status', '=', 1];
        $where[] = ['type', '=', 3];
        $where[] = ['id', 'in', $ids];
        $model = new AuthNode();
        $list = $model->where($where)->select();

        if ($list->isEmpty()) {
            return [];
        } else {

            return $list->toArray();
        }
    }
}